<template>
	<view class="container">
		<view class="top-functions">
			<view class="icon-item">
				<image src="../../static/fabu.png"></image>
				<text @click="huoyuan">发布货源</text>
			</view>
			<view class="icon-item">
				<image src="../../static/shuiyinxiangji.png"></image>
				<text @click="shuiyin">水印相机</text>
			</view>
			<view class="icon-item">
				<image src="../../static/saoyisao.png"></image>
				<text @click="sao">扫一扫</text>
			</view>
		</view>

		<!-- 认证状态显示区域 -->
		<view class="auth-container">
			<!-- 根据认证进度显示不同的提示 -->
			<view v-if="!isAuthenticated" class="auth-text">
				<image src="/static/images/实名认证-未认证.png"></image>
				<text>您尚未完成实名认证，请先完成实名认证</text>
				<button class="auth-button" @click="goToAuthentication('实名认证')">实名认证</button>
			</view>

			<view v-else-if="isAuthenticated && !isCompanyAuthenticated" class="auth-text">
				<image src="/static/images/企业认证-未认证.png"></image>
				<text>您已完成实名认证，但尚未完成企业认证，请先完成企业认证</text>
				<button class="auth-button" @click="goToAuthentication('企业认证')">企业认证</button>
			</view>

			<view v-else-if="isAuthenticated && isCompanyAuthenticated && !isLegalPersonAuthenticated"
				class="auth-text">
				<image src="/static/images/法人认证-未认证.png"></image>
				<text>您已完成实名认证和企业认证，但尚未完成法人认证，请先完成法人认证</text>
				<button class="auth-button" @click="goToAuthentication('法人认证')">法人认证</button>
			</view>

			<view v-else class="auth-text">
				<image src="/static/images/实名认证-已认证.png"></image>
				<text>您已成功完成所有认证，以下是您的货源信息</text>
				<!-- 这里可以添加货源信息展示 -->
				<view class="goods-info">
					<!-- 货源信息内容 -->
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue';
	import { useuser } from '../../stores/user';
	const user = useuser();

	// 响应式变量，用于存储用户认证状态
	const isAuthenticated = ref(false); // 实名认证
	const isCompanyAuthenticated = ref(false); // 企业认证
	const isLegalPersonAuthenticated = ref(false); // 法人认证

	// 从后端获取认证状态
	const fetchAuthStatus = async () => {
		try {
			const response = await uni.request({
				url: 'https://your-backend-api.com/get-auth-status', // 替换为你的后端接口
				method: 'GET',
				header: {
					'Authorization': 'Bearer your-token' // 替换为你的认证令牌
				}
			});

			const {
				data
			} = response[1];
			if (data) {
				isAuthenticated.value = data.isAuthenticated;
				isCompanyAuthenticated.value = data.isCompanyAuthenticated;
				isLegalPersonAuthenticated.value = data.isLegalPersonAuthenticated;
			}
		} catch (error) {
			console.error('获取认证状态失败:', error);
		}
	};

	// 页面加载时获取认证状态
	
	onMounted(() => {
		fetchAuthStatus();
		
		const id= user.user.id;
	});

	// 跳转到认证页面
	const goToAuthentication = (authType) => {
		let url;
		switch (authType) {
			case '实名认证':
				url = '/pages/homepage/pageinfo/shimingrenzheng';
				break;
			case '企业认证':
				url = '/pages/homepage/pageinfo/qiyerenzheng';
				break;
			case '法人认证':
				url = '/pages/my/pageinfo/farenrenzheng';
				break;
			default:
				url = '/pages/my/pageinfo/farenrenzheng';
		}
		uni.navigateTo({
			url: url
		});
	};

	// 跳转到发布货源页面
	const huoyuan = () => {
		uni.navigateTo({
			url: '/pages/sourceofgoods/pageinfo/fabu'
		});
	};

	// 其他方法保持不变
	const shuiyin = () => {
		// 水印相机功能实现
	};

	const sao = () => {
		// 扫一扫功能实现
	};
</script>

<style>
	.container {
		background-color: #eeeeee;
		display: flex;
		flex-wrap: wrap;
		justify-content: space-around;
		flex-direction: column;
		padding: 15px;
	}

	.top-functions {
		display: flex;
		justify-content: space-around;
		margin-bottom: 20px;
		background-color: #ffffff;
		padding: 15px 0;
		border-radius: 10px;
	}

	.icon-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin: 10px;
	}

	.icon-item image {
		width: 48px;
		height: 48px;
	}

	.icon-item text {
		margin-top: 5px;
		text-align: center;
		font-size: 14px;
		color: #333;
	}

	.auth-container {
		width: 100%;
		height: 69vh;
		background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
		border-radius: 10px;
		padding: 20px;
		box-sizing: border-box;
		box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
	}

	.auth-text {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		border: 1px solid #e0e0e0;
		margin-bottom: 10px;
		margin-top: 150rpx;
		padding: 20px;
		border-radius: 15px;
		box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
		background-color: #ffffff;
	}

	.auth-text image {
		width: 70px;
		height: 70px;
		margin-bottom: 15px;
		border-radius: 50%;
		box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
		background-color: #f5f5f5;
	}

	.auth-text text {
		font-size: 16px;
		color: #333;
		margin-bottom: 20px;
		text-align: center;
	}

	.auth-button {
		background-color: #007AFF;
		color: white;
		padding: 12px 30px;
		border: none;
		border-radius: 20px;
		font-size: 16px;
		width: 80%;
		margin-top: 10px;
		box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
		transition: background-color 0.3s ease;
	}

	.auth-button:hover {
		background-color: #005bb5;
	}

	.goods-info {
		margin-top: 20px;
		width: 100%;
		/* 货源信息样式可以根据实际需求添加 */
	}
</style>